import os
import pickle
import numpy as np

data_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'data'))
features_path = os.path.join(data_path, 'image_features')

def load_index():
    indices = {}
    for i in range(100):
        path = os.path.join(features_path, f"cache_feature{i}.bin")
        with open(path, 'rb') as fp:
            tmp_datas = pickle.load(fp)
            for data in tmp_datas:
                id = data['id']
                features = data['features']
                path = data['path']
                indices[id] = (features, path)
    return indices

def load_invert_index():
    with open(os.path.join(data_path, 'invert_indices.bin'), 'rb') as fp:
        invert_indices = pickle.load(fp)
    return invert_indices